package mylab.utils.spring.spi;

import com.google.common.collect.Maps;
import lombok.Data;

import java.util.HashMap;

@Data
public abstract class AbstractProperties implements SpiProperties {

    /**
     * 是否启用
     */
    private boolean enabled;

    /**
     * 扩展属性
     */
    private HashMap<String, ?> attrs = Maps.newHashMap();

    @SuppressWarnings("unchecked")
    @Override
    public <T> T getAttr(String attrKey) {
        return (T) attrs.get(attrKey);
    }

    public <T> T getAttr(String attrKey, T defaultValue) {
        return attrs.containsKey(attrKey) ? getAttr(attrKey) : defaultValue;
    }
}
